from lib import *

class Act(object):
  """
  An Act connects States 'here' to 'there'. 

  All the Acts for one state are explored in an order biased by 
  'priority' (and higher priority acts get explored first). 

  Acts have 'gaurds' that check for relevance (default=True).

  Acts have 'actions' that fire if the guard is satisfied (default=noop).
  If an Act fires, then a text 'tag' is printed.
  """
  def __init__(self,here,there,tag,priority=1,guard=True,fx=noop) :
    """Constructor. When creating a new Act, it is always installed
    into the outs list of the 'here' state."""
    self.there = there
    self.here  = here
    self.tag   = tag
    self.guard = guard
    self.fx    = fx
    self.priority = priority
    self.here.out(self)

  def sideEffect(self):
    """Fire the side-effect associated with performing this Act."""
    return val(self.fx)

  def ready(self) :
    """Check if this Act is ready to run."""
    return val(self.guard)

  def __repr__(self):
    """Pretty print an Act"""
    return (str(self.here) + ' to ' + 
            str(self.there) + ' [' + 
            str(self.tag) + '] * ' +
            str(self.priority))
    
